/*
 * @Author: your name
 * @Date: 2020-09-08 15:27:35
 * @LastEditTime: 2020-09-08 15:56:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /sort/SelectionSort.cpp
 */
#include <iostream>
using namespace std;

//选择排序1
void SelectionSort1(int arry[])
{
    int len=(sizeof(arry)/sizeof(arry[0]));  //定义数组长度
    for(int i=0;i<len;i++)
	{
        for(int j=0;j<len;j++)
        {
            if(arry[i]<arry[j])//进行比较
            //比较后进行交换
            {
                int temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
    }
}

//选择排序2
void SelectionSort2(int arry[])
{
    int len=(sizeof(arry)/sizeof(arry[0]));  //定义数组长度
    for (int end =len-1;end >0;end--)     /* code */
    {
        int maxIndex=0;
        for (int begin = 1; begin <=end;begin++)
        {
            if(arry[maxIndex]<=arry[begin])
                maxIndex=begin;
        }
        int temp=arry[maxIndex];
        arry[maxIndex]=arry[end];
        arry[end]=temp;
    }
}


int main()
{
    int arry[6]={30,17,89,67,45,59};
    //SelectionSort1(arry);
    SelectionSort2(arry);
    for (int i = 0; i <6; i++)
    {
        cout<<arry[i]<<" ";
    }
    cout<<endl;
    return 0;
}